import type { Recordable } from '@vben/types';

import { requestClient } from '#/api/request';

export namespace SystemUserApi {
  export interface User {
    [key: string]: any;
    id: string;
    username: string;
    alias?: string;
    email: string;
    phone?: string;
    dept_id: number;
    dept?: string;
    status: 0 | 1;
    is_superuser?: boolean;
    last_login?: string;
    created_at: string;
    updated_at: string;
    role_ids?: number[];
  }
}

/**
 * 获取用户列表数据
 */
async function getUserList(params: Recordable<any>) {
  return requestClient.get<{
    data: Array<SystemUserApi.User>;
    page: number;
    page_size: number;
    total: number;
  }>('/v1/user/pages', { params });
}

/**
 * 根据ID获取用户详情
 */
async function getUserById(id: number | string) {
  return requestClient.get<SystemUserApi.User>(`/v1/user/${id}`);
}

/**
 * 创建用户
 */
async function createUser(data: SystemUserApi.User) {
  return requestClient.post('/v1/user/', data);
}

/**
 * 更新用户
 */
async function updateUser(data: SystemUserApi.User) {
  return requestClient.put('/v1/user/', data);
}

/**
 * 删除用户
 */
async function deleteUser(id: number | string) {
  return requestClient.delete(`/v1/user/${id}`);
}

/**
 * 重置密码
 */
async function resetPassword(user_id: number) {
  return requestClient.post('/v1/user/reset_password', { user_id });
}

export {
  createUser,
  deleteUser,
  getUserById,
  getUserList,
  resetPassword,
  updateUser,
};
